package com.liang.gaoji;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @Author:liangli
 * @Date:2020/11/21 16:14
 */
//回顾总结线程的创建
public class ThreadNew {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        new MyThread1().start();
        new Thread(new MyThread2()).start();
        FutureTask<Integer> futureTask=new FutureTask<Integer>(new MyThread3());
        new Thread(futureTask).start();
        Integer integer = futureTask.get();
        System.out.println(integer);
    }
}

//1.继承thread类
class MyThread1 extends Thread{
    @Override
    public void run() {
        System.out.println("这是集成thread类");
    }
}

//2.实现runable
class MyThread2 implements Runnable{
    @Override
    public void run() {
        System.out.println("这是实现runnable接口创建线程");
    }
}

//3.实现callable
class MyThread3 implements Callable<Integer>{
    @Override
    public Integer call() throws Exception {
        return 3;

    }
}